1 package mobisnap.mobile_trx; 2 3 public class RelopCondition 4 extends ColumnCondition 5 implements java.io.Serializable 6 { 7 public static final int OP_EQUAL = 1; 8 public static final int OP_NOTEQUAL = 2; 9 public static final int OP_CARDINAL = 3; 10 public static final int OP_MOREORLESS = 4; 11 public static final int OP_MORE = 5; 12 public static final int OP_MOREEQUAL = 6; 13 public static final int OP_LESS = 7; 14 public static final int OP_LESSEQUAL = 8; 15 16 String columnName; 17 int relop; 18 Object value; 19 20 public RelopCondition( String columnName, int relop, Object value) { 21 this.columnName = columnName.trim(); 22 this.relop = relop; 23 this.value = value; 24 } 25 26 /*** 27 * Returns true if this condition is the same that is represented by the 28 * given node 29 */ 30 public boolean sameCondition( SimpleNode node) { 31 if( node instanceof ASTSQLRelationalExpression) { 32 ASTSQLRelationalExpression expr = (ASTSQLRelationalExpression)node; 33 if( expr.firstprior || expr.secondprior || expr.type != 1 || 34 expr.secondquery) 35 return false; 36 if ( ((ASTRelop)expr.v1).type != ASTRelop.OP_EQUAL ) 37 return belongsTo( new RelopCondition( expr.first.toString( mobisnap.MobisnapConstants.MSQL_SERVER).trim() , ((ASTRelop)expr.v1).type, ((SimpleNode)expr.v2).toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim() )); 38 39 Object obj1 = null; 40 Object obj2 = null; 41 42 try { 43 obj1 = expr.first.value( mobisnap.MobisnapConstants.MSQL_SERVER, false); 44 } catch( Exception e) { 45 obj1 = expr.first.toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim(); 46 } 47 try { 48 obj2 = ((SimpleNode)expr.v2).value( mobisnap.MobisnapConstants.MSQL_SERVER, false); 49 } catch( Exception e) { 50 obj2 = ((SimpleNode)expr.v2).toString( mobisnap.MobisnapConstants.MSQL_SERVER). trim(); 51 } 52 if( obj1 instanceof String && obj2 instanceof String) { 53 if( columnName.equals( ((String)obj1).trim())) 54 obj1 = obj2; 55 else if( ! columnName.equals( ((String)obj2).trim())) 56 return false; 57 } else if( obj1 instanceof String) { 58 if( columnName.equals( ((String)obj1).trim())) 59 obj1 = obj2; 60 else 61 return false; 62 } else if( obj2 instanceof String) { 63 if( ! columnName.equals( ((String)obj2).trim())) 64 return false; 65 } 66 67 try { 68 Object obj = MSQLTypeUtil.equal( obj1, value); 69 if( obj instanceof Boolean) { 70 return ((Boolean)obj).booleanValue(); 71 } 72 } catch( Exception e) { 73 return false; 74 } 75 return false; 76 } else 77 return false; 78 } 79 80 /*** 81 * Returns true if this condition intersected with the given node equals 82 * the given condition, resulting int the fact that the given node "belongs" to this condition 83 */ 84 public boolean belongsTo( RelopCondition cond) { 85 86 if (!cond.columnName.equals(columnName)) 87 return false; 88 89 if ( cond.relop == OP_EQUAL && relop == OP_EQUAL) { 90 try { 91 Object obj = MSQLTypeUtil.equal( cond.value, value); 92 if( obj instanceof Boolean) { 93 return ((Boolean)obj).booleanValue(); 94 } 95 } catch( Exception e) { 96 return false; 97 } 98 } 99 100 if ( ( cond.relop == OP_MORE || cond.relop == OP_MOREEQUAL ) && ( relop == OP_MORE || relop == OP_MOREEQUAL || relop == OP_EQUAL) ) { 101 try { 102 Object obj = MSQLTypeUtil.moreEqual( value, cond.value); 103 if( obj instanceof Boolean) { 104 return ((Boolean)obj).booleanValue(); 105 } 106 } catch( Exception e) { 107 return false; 108 } 109 } 110 111 if ( ( cond.relop == OP_LESS || cond.relop == OP_LESSEQUAL ) && ( relop == OP_LESS || relop == OP_LESSEQUAL || relop == OP_EQUAL) ) { 112 try { 113 Object obj = MSQLTypeUtil.lessEqual( value, cond.value); 114 if( obj instanceof Boolean) { 115 return ((Boolean)obj).booleanValue(); 116 } 117 } catch( Exception e) { 118 return false; 119 } 120 } 121 return false; 122 } 123 124 public void sourceCode( StringBuffer buffer) { 125 buffer.append( columnName); 126 switch( relop) { 127 case OP_EQUAL: 128 buffer.append( " = "); 129 break; 130 case OP_NOTEQUAL: 131 buffer.append( " != "); 132 break; 133 case OP_CARDINAL: 134 buffer.append( " # "); 135 break; 136 case OP_MOREORLESS: 137 buffer.append( " <> "); 138 break; 139 case OP_MORE: 140 buffer.append( " > "); 141 break; 142 case OP_MOREEQUAL: 143 buffer.append( " >= "); 144 break; 145 case OP_LESS: 146 buffer.append( " < "); 147 break; 148 case OP_LESSEQUAL: 149 buffer.append( " <= "); 150 break; 151 } 152 buffer.append( MSQLTypeUtil.value2String( value)); 153 } 154 155 public String toString() { 156 StringBuffer buffer = new StringBuffer(); 157 sourceCode( buffer); 158 return buffer.toString(); 159 } 160 }

This page was automatically generated by Maven